<?php 
class Custom_Controller_Plugin_LayoutManager extends Zend_Controller_Plugin_Abstract{
	
	public function dispatchLoopStartup (Zend_Controller_Request_Abstract $request)
    {	
    	$module = $request->getModuleName();
		
    	$layout = Zend_Layout::getMvcInstance();
    	if ($layout->getMvcEnabled())
		{
			$layout->setLayoutPath(APPLICATION_PATH . '/layouts/scripts');
			$layout->setLayout($module);
		}
		
		$layout->getView()->doctype('XHTML1_STRICT');
		$layout->getView()->headTitle($module);
		
		$module = "skin_1"; //Temporary Measure;
    	$skinData = new Zend_Config_Xml(APPLICATION_PATH . '/../public/skins/' . $module . '/skin.xml');
		$stylesheets = $skinData->stylesheets->stylesheet->toArray();
		
		//append each stylesheet
		if(is_array($stylesheets))
		{
			foreach($stylesheets as $stylesheet)
			{
				$layout->getView()->headLink()->appendStylesheet('/skins/' . $module . '/css/' . $stylesheet);
			}
		}
		
	}
	
}